<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="tradeId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['tradeId', validatorRules.tradeId]" placeholder="请输入tradeId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="tradeParentId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['tradeParentId']" placeholder="请输入tradeParentId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="numIid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['numIid']" placeholder="请输入numIid" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="itemTitle" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['itemTitle']" placeholder="请输入itemTitle"></a-input>
        </a-form-item>
        <a-form-item label="itemNum" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['itemNum']" placeholder="请输入itemNum" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="price" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['price']" placeholder="请输入price"></a-input>
        </a-form-item>
        <a-form-item label="payPrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['payPrice']" placeholder="请输入payPrice"></a-input>
        </a-form-item>
        <a-form-item label="sellerNick" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sellerNick']" placeholder="请输入sellerNick"></a-input>
        </a-form-item>
        <a-form-item label="sellerShopTitle" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sellerShopTitle']" placeholder="请输入sellerShopTitle"></a-input>
        </a-form-item>
        <a-form-item label="commission" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commission']" placeholder="请输入commission"></a-input>
        </a-form-item>
        <a-form-item label="commissionRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commissionRate']" placeholder="请输入commissionRate"></a-input>
        </a-form-item>
        <a-form-item label="unid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['unid']" placeholder="请输入unid"></a-input>
        </a-form-item>
        <a-form-item label="createTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['createTime']" placeholder="请输入createTime"></a-input>
        </a-form-item>
        <a-form-item label="earningTime" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['earningTime']" placeholder="请输入earningTime"></a-input>
        </a-form-item>
        <a-form-item label="tkStatus" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['tkStatus']" placeholder="请输入tkStatus" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="tk3rdType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tk3rdType']" placeholder="请输入tk3rdType"></a-input>
        </a-form-item>
        <a-form-item label="tk3rdPubId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['tk3rdPubId']" placeholder="请输入tk3rdPubId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="orderType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['orderType']" placeholder="请输入orderType"></a-input>
        </a-form-item>
        <a-form-item label="incomeRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['incomeRate']" placeholder="请输入incomeRate"></a-input>
        </a-form-item>
        <a-form-item label="pubSharePreFee" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['pubSharePreFee']" placeholder="请输入pubSharePreFee"></a-input>
        </a-form-item>
        <a-form-item label="subsidyRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['subsidyRate']" placeholder="请输入subsidyRate"></a-input>
        </a-form-item>
        <a-form-item label="subsidyType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['subsidyType']" placeholder="请输入subsidyType"></a-input>
        </a-form-item>
        <a-form-item label="terminalType" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['terminalType']" placeholder="请输入terminalType"></a-input>
        </a-form-item>
        <a-form-item label="auctionCategory" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['auctionCategory']" placeholder="请输入auctionCategory"></a-input>
        </a-form-item>
        <a-form-item label="siteId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['siteId']" placeholder="请输入siteId"></a-input>
        </a-form-item>
        <a-form-item label="siteName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['siteName']" placeholder="请输入siteName"></a-input>
        </a-form-item>
        <a-form-item label="adzoneId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['adzoneId']" placeholder="请输入adzoneId"></a-input>
        </a-form-item>
        <a-form-item label="adzoneName" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['adzoneName']" placeholder="请输入adzoneName"></a-input>
        </a-form-item>
        <a-form-item label="alipayTotalPrice" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['alipayTotalPrice']" placeholder="请输入alipayTotalPrice"></a-input>
        </a-form-item>
        <a-form-item label="totalCommissionRate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['totalCommissionRate']" placeholder="请输入totalCommissionRate"></a-input>
        </a-form-item>
        <a-form-item label="totalCommissionFee" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['totalCommissionFee']" placeholder="请输入totalCommissionFee"></a-input>
        </a-form-item>
        <a-form-item label="subsidyFee" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['subsidyFee']" placeholder="请输入subsidyFee"></a-input>
        </a-form-item>
        <a-form-item label="relationId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['relationId']" placeholder="请输入relationId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="specialId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['specialId']" placeholder="请输入specialId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="pictUrl" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['pictUrl']" rows="4" placeholder="请输入pictUrl"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  
  export default {
    name: "TbMnOrderModal",
    components: { 
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          tradeId: {
            rules: [
              { required: true, message: '请输入tradeId!'},
            ]
          },
        },
        url: {
          add: "/mall/tbMnOrder/add",
          edit: "/mall/tbMnOrder/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'tradeId','tradeParentId','numIid','itemTitle','itemNum','price','payPrice','sellerNick','sellerShopTitle','commission','commissionRate','unid','createTime','earningTime','tkStatus','tk3rdType','tk3rdPubId','orderType','incomeRate','pubSharePreFee','subsidyRate','subsidyType','terminalType','auctionCategory','siteId','siteName','adzoneId','adzoneName','alipayTotalPrice','totalCommissionRate','totalCommissionFee','subsidyFee','relationId','specialId','pictUrl'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'tradeId','tradeParentId','numIid','itemTitle','itemNum','price','payPrice','sellerNick','sellerShopTitle','commission','commissionRate','unid','createTime','earningTime','tkStatus','tk3rdType','tk3rdPubId','orderType','incomeRate','pubSharePreFee','subsidyRate','subsidyType','terminalType','auctionCategory','siteId','siteName','adzoneId','adzoneName','alipayTotalPrice','totalCommissionRate','totalCommissionFee','subsidyFee','relationId','specialId','pictUrl'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>